package com.surfilter.mq.job.start;

import com.surfilter.funds.task.job.StatCountBaseJob;
import com.surfilter.funds.task.manage.rocketmq.RocketMqConfig;
import com.surfilter.funds.task.manage.rocketmq.cache.RockMqMesgManage;
import com.surfilter.funds.task.manage.rocketmq.exe.RocketMesgExecute;
import com.surfilter.funds.task.manage.rocketmq.exe.RocketMesgExecute.ExecuteModel;
import com.surfilter.funds.task.util.PropertiesUtils;
import com.surfilter.mq.job.StatCountBaseJob;
import com.surfilter.mq.validate.oprat.WebSiteStatusOperate;
import com.surfilter.mq.validate.website.WebSiteStatusService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ValidateLiveRecieveTaskJob extends StatCountBaseJob {

	private static final Logger logger = LoggerFactory.getLogger(ValidateLiveRecieveTaskJob.class);
	private WebSiteStatusService webSiteStatusService;
	private RocketMesgExecute execute;
	private static RockMqMesgManage manage = new RockMqMesgManage(500);
	private static final String group = PropertiesUtils.getStringValue("testwebsite.validate.group", "testws_vali_group");
	private static final String topic = PropertiesUtils.getStringValue("testwebsite.validate.topic", "testws_vali");
	private static final String tags = PropertiesUtils.getStringValue("", "*");
	private static final String namesrvAddr = PropertiesUtils.getStringValue("rocketmq.namesrv", "");
	private static final String instanceName = PropertiesUtils.getStringValue("testwebsite.validate.intance.name", "testwebsitevalidate");
	private static final int batchSize = PropertiesUtils.getIntValue("batchSize", 1);
	private static final int threadNum = PropertiesUtils.getIntValue("threadNum.test_validate-Live", 45);

	public void work(){
		if(!super.isEnable())return;
		try{
			logger.info("测试------开始初始化网站验活及一些状态判断定时任务...");
			initExecute();
			logger.info("测试------初始化网站验活及一些状态判断任务开始执行...");
			execute.start();
			logger.info("测试------执行网站验活及一些状态判断任务完成...");
		}catch(Exception e){
			e.printStackTrace();
			logger.error("测试------网站验活及一些状态判断任务执行异常..{}", e);
		}
	}
	
	private void initExecute() throws Exception{
		if(execute == null || !execute.isInit_type()){
			String name = "Test----ValidateLive";
			RocketMqConfig config = new RocketMqConfig(group, topic, tags, namesrvAddr, instanceName, batchSize);
			WebSiteStatusOperate r_oprate = new WebSiteStatusOperate(null, manage);
			r_oprate.setWebSiteStatusService(webSiteStatusService);
			execute = new RocketMesgExecute(name, config, manage, r_oprate, threadNum, ExecuteModel.Blocking_queue);
			execute.init();
		}
	}

	public WebSiteStatusService getWebSiteStatusService() {
		return webSiteStatusService;
	}

	public void setWebSiteStatusService(WebSiteStatusService webSiteStatusService) {
		this.webSiteStatusService = webSiteStatusService;
	}

	
}
